﻿Imports System.Collections.ObjectModel

Public Class MostRecentFile
    Implements ComponentModel.INotifyPropertyChanged

    Public Property PageNumber As Integer

    Public Sub New(ByVal filePath As String, ByVal isFixed As Boolean, ByVal pageNumber As Integer)
        Me.FilePath = filePath
        Me.IsFixed = isFixed
        Me.Name = IO.Path.GetFileName(filePath)
        Me.PageNumber = pageNumber
    End Sub

    Public Sub New(ByVal filePath As String, ByVal isFixed As Boolean)
        Me.PageNumber = 0
        Me.FilePath = filePath
        Me.IsFixed = isFixed
        Me.Name = IO.Path.GetFileName(filePath)
    End Sub

    Public Property Name() As String
        Get
            Return _name
        End Get
        Set(ByVal value As String)
            _name = value
            Me.OnPropertyChanged("Name")
        End Set
    End Property
    Private _name As String

    Public Property IsFixed() As Boolean
        Get
            Return _isFixed
        End Get
        Set(ByVal value As Boolean)
            _isFixed = value
            Me.OnPropertyChanged("IsFixed")
        End Set
    End Property
    Private _isFixed As Boolean

    Public Property FilePath() As String
        Get
            Return _filePath
        End Get
        Set(ByVal value As String)
            _filePath = value
            Me.OnPropertyChanged("FilePath")
        End Set
    End Property
    Private _filePath As String

    Public Event PropertyChanged(ByVal sender As Object, ByVal e As System.ComponentModel.PropertyChangedEventArgs) Implements System.ComponentModel.INotifyPropertyChanged.PropertyChanged
    Public Overridable Sub OnPropertyChanged(ByVal propertyName As String)
        RaiseEvent PropertyChanged(Me, New ComponentModel.PropertyChangedEventArgs(propertyName))
    End Sub
End Class

Public Class MostRecentFiles
    Inherits ObservableCollection(Of MostRecentFile)

    Public MaxCount As Integer = 5

    Public Sub Append(ByVal item As MostRecentFile)
        For Each c As MostRecentFile In Me.Items
            If String.Compare(c.FilePath, item.FilePath, True) = 0 Then
                Exit Sub
            End If
        Next
        If Me.Items.Count >= MaxCount Then
            Me.Items.RemoveAt(0)
        End If
        Me.Items.Add(item)
    End Sub

End Class